﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using pay.Entity;
using pay.BLL;
using System.Text;

public partial class ePoineer_shopping1 : System.Web.UI.Page
{
    List<ShopCard> lst = new List<ShopCard>();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Session["Ordernumber"] = null;
            if (Session["EmoneyShopCard"] == null || ((List<ShopCard>)Session["EmoneyShopCard"]).Count == 0)
            {
                str_products.InnerHtml = "<center>没有任何商品</center>";
                sums.InnerHtml = "订单合计 RMB 0元";
                return;
            }
            str_products.InnerHtml = getList().ToString();
            sums.InnerHtml = "订单合计 RMB " + sum + "元";
        }
    }

    
    ShopCard sc = new ShopCard();
    public double sum = 0;
    ProductBLL bll = new ProductBLL();
    public StringBuilder getList()
    {
        StringBuilder sb = new StringBuilder();
        List<ShopCard> list = new List<ShopCard>();
        list = (List<ShopCard>)Session["EmoneyShopCard"];
        if (list == null) { return sb; }
        foreach (var c in list)
        {
            Product product = bll.GetElementById(c.ProductId);
            try
            {
                c.ProductName = product.Productname;
                c.Price = product.Nowprice.Value;
                sum += c.Amount;
                sb.AppendLine("<div class=\"clear\"></div><div class=\"cx_main1_ban1\">");
                sb.AppendLine("<div class=\"cx_main1_fen1 fl\">" + c.ProductName + "</div>");
                sb.AppendLine("<div class=\"cx_main1_fen2 fl\">RMB " + c.Price + "元</div>");
                sb.AppendLine("<div class=\"cx_main1_fen3_1 fl\">");

                sb.AppendLine("<div class=\"cx_main1_jia fl\"><img src=\"img/cx_612.jpg\" width=\"13\" height=\"13\" style=\"cursor: pointer\" onclick=\"xun_jian(" + c.ProductId + ")\" /></div>");

                sb.AppendLine("<div class=\"cx_main1_kuangg fl\"><input maxlength=\"4\" id=\"counts" + c.ProductId + "\"  price=\"" + c.Price + "\" pid=\"" + c.ProductId + "\" name=\"counts\" type=\"text\" class=\"cx_main1_kuang\" style=\"text-align: center; padding-top: 3px;\"  value=\"" + c.Count + "\" onblur=\"InputOnBlur(this);\" /></div>");
                sb.AppendLine("<div class=\"cx_main1_jian fl\"><img src=\"img/cx_613.jpg\" width=\"13\" height=\"13\" style=\"cursor: pointer\" onclick=\"xun_zeng(" + c.ProductId + ")\" /></div><span id=\"ck_count" + c.ProductId + "\" style=\"color:#cc3300;\"></span>");

                sb.AppendLine("</div><div class=\"cx_main1_fen4 fl\" id=\"amount" + c.ProductId + "\">RMB " + c.Amount + "元</div><div class=\"cx_main1_fen5 fl\">");

                sb.AppendLine("<img pid='" + c.ProductId + "' id=\"del\" src=\"img/cx_611.jpg\" width=\"14\" height=\"14\" onclick=\"deleteTr(this)\" style=\"cursor: pointer\" /></div></div>");
            }
            catch (Exception ex)
            {
                list.Remove(c);
                Session["EmoneyShopCard"] = list;
                sb.AppendLine("系统错误: " + ex.Message);
                break;
            }

        }
        return sb;
    }

    
        
            
           
            
                
                    
    
}